

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.hre.db.dao.EmpDependentDAO;
import com.edu.hre.db.dao.EmpEmergencyContactDAO;
import com.edu.hre.db.dao.EmployeeDAO;
import com.edu.hre.db.dao.LeaveDAO;
import com.edu.hre.db.dto.HreEmpDependent;
import com.edu.hre.db.dto.HreEmpEmergencyContact;
import com.edu.hre.db.dto.HreEmployee;
import com.edu.hre.db.dto.HreLeaveRequest;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

/**
 * Servlet implementation class EmployeeServlet
 */
public class YourLeaveGetServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public YourLeaveGetServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
				int userId = Integer.parseInt(request.getParameter("userId"));
		List<HreLeaveRequest> leaveRequestList = new LeaveDAO().getLeaveListByUserId(userId);
		Gson gson = new Gson();
		  JsonObject myObj = new JsonObject();
		  myObj.addProperty("success", true);
		  myObj.add("leaveRequests", gson.toJsonTree(leaveRequestList));
		  myObj.addProperty("totalCount", leaveRequestList.size());
		  response.setContentType("text/html");
		  response.getWriter().println(myObj.toString());
		  response.getWriter().close();
	}

}
